Skip to content

[mypy] Fix type annotations in data_structures/binary_tree #5518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

shermanhui
Copy link
Contributor

@shermanhui shermanhui commented Oct 22, 2021

fix type annotations in data_structures/binary_tree/binary_search_tree.py and data_structures/binary_tree/merge_two_binary_trees.py

My contribution to fixing the mypy errors identified in #4052

Update binary_search_tree arr argument to be typed as a list
within find_kth_smallest function

Update return type of merge_two_binary_trees as both inputs can
be None which means that a None type value can be returned from
this function

Screen Shot 2021-10-21 at 21 42 03

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

shermanhui and others added 2 commits October 21, 2021 21:42
Update binary_search_tree `arr` argument to be typed as a list
within `find_kth_smallest` function

Update return type of `merge_two_binary_trees` as both inputs can
be None which means that a None type value can be returned from
this function
@ghost ghost added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Oct 22, 2021
Copy link
Member

@poyea poyea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your pull request!🤩Let's make it --strict? It's not a strict requirement though:

> mypy . --ignore-missing-imports --strict
binary_search_tree.py:7: error: Function is missing a type annotation
binary_search_tree.py:13: error: Function is missing a return type annotation
binary_search_tree.py:22: error: Function is missing a type annotation
binary_search_tree.py:25: error: Function is missing a return type annotation
binary_search_tree.py:31: error: Function is missing a type annotation
binary_search_tree.py:35: error: Call to untyped function "is_right" in typed context
binary_search_tree.py:42: error: Function is missing a type annotation
binary_search_tree.py:45: error: Function is missing a return type annotation
binary_search_tree.py:48: error: Function is missing a type annotation
binary_search_tree.py:52: error: Call to untyped function "Node" in typed context
binary_search_tree.py:53: error: Call to untyped function "empty" in typed context
binary_search_tree.py:72: error: Function is missing a type annotation
binary_search_tree.py:74: error: Call to untyped function "__insert" in typed context
binary_search_tree.py:77: error: Function is missing a type annotation
binary_search_tree.py:78: error: Call to untyped function "empty" in typed context
binary_search_tree.py:87: error: Function is missing a type annotation
binary_search_tree.py:93: error: Call to untyped function "empty" in typed context
binary_search_tree.py:98: error: Function is missing a type annotation
binary_search_tree.py:104: error: Call to untyped function "empty" in typed context
binary_search_tree.py:110: error: Function is missing a type annotation
binary_search_tree.py:111: error: Call to untyped function "search" in typed context
binary_search_tree.py:114: error: Call to untyped function "__reassign_nodes" in typed context
binary_search_tree.py:116: error: Call to untyped function "__reassign_nodes" in typed context
binary_search_tree.py:118: error: Call to untyped function "__reassign_nodes" in typed context
binary_search_tree.py:120: error: Call to untyped function "get_max" in typed context
binary_search_tree.py:123: error: Call to untyped function "remove" in typed context
binary_search_tree.py:128: error: Function is missing a type annotation
binary_search_tree.py:131: error: Call to untyped function "preorder_traverse" in typed context
binary_search_tree.py:132: error: Call to untyped function "preorder_traverse" in typed context
binary_search_tree.py:134: error: Function is missing a type annotation
binary_search_tree.py:140: error: Call to untyped function "preorder_traverse" in typed context
binary_search_tree.py:144: error: Function is missing a return type annotation
binary_search_tree.py:144: error: Missing type parameters for generic type "list"
binary_search_tree.py:148: error: Argument 2 to "inorder" of "BinarySearchTree" has incompatible type "Optional[Any]"; expected "Node"
binary_search_tree.py:150: error: Argument 2 to "inorder" of "BinarySearchTree" has incompatible type "Optional[Any]"; expected "Node"
binary_search_tree.py:154: error: Missing type parameters for generic type "list"
binary_search_tree.py:156: error: Returning Any from function declared to return "int"
binary_search_tree.py:159: error: Function is missing a type annotation
binary_search_tree.py:165: error: Call to untyped function "postorder" in typed context
binary_search_tree.py:169: error: Function is missing a return type annotation
binary_search_tree.py:169: note: Use "-> None" if function does not return a value
binary_search_tree.py:191: error: Call to untyped function "BinarySearchTree" in typed context
binary_search_tree.py:193: error: Call to untyped function "insert" in typed context
binary_search_tree.py:198: error: Call to untyped function "search" in typed context
binary_search_tree.py:203: error: Call to untyped function "search" in typed context
binary_search_tree.py:208: error: Call to untyped function "empty" in typed context
binary_search_tree.py:209: error: Call to untyped function "get_max" in typed context
binary_search_tree.py:210: error: Call to untyped function "get_min" in typed context
binary_search_tree.py:213: error: Call to untyped function "remove" in typed context
Found 48 errors in 1 file (checked 3 source files)

@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Oct 22, 2021
@poyea poyea added the awaiting merge This PR is approved and ready to be merged label Oct 22, 2021
@ghost ghost removed the awaiting merge This PR is approved and ready to be merged label Oct 22, 2021
@l3str4nge l3str4nge merged commit 629848e into TheAlgorithms:master Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants